import {
  request
} from "../../request/index.js";
import regeneratorRuntime from "../../lib/runtime/runtime";
import {
  login
} from "../../utils/asyncWx.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  async handleGetUserInfo(e) {
    try {
      // 1获取用户信息
      const {
        encryptedData,
        rawData,
        iv,
        signature
      } = e.detail;
      //2获取小程序登录成功后的codeI
      const {
        code
      } = await login();
      const loginParams = {
        encryptedData,
        rawData,
        iv,
        signature,
        code
      };
      // 3发送请求获取用户的token
      const token = await request({
        url: "/users/wxlogin",
        data: loginParams,
        method: "post"
      });
      wx.setStorageSync('token', token);
      wx.navigateBack({
        delta: 1,
      })
    } catch (error) {

    }
  },
})